package com.coder520.controller;

import com.coder520.common.Const;
import com.coder520.common.ResponseCode;
import com.coder520.common.ServerResponse;
import com.coder520.pojo.Attend;
import com.coder520.pojo.User;
import com.coder520.service.IAttendService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by ASUS on 2017/7/4.
 */
@Controller
@RequestMapping("/attend")
public class AttendController {

    @Autowired
    private IAttendService iAttendService;

    /**
     * 跳转打卡页面
     * @return
     */
    @RequestMapping("/home")
    public String attendHome(){
        return "attend";
    }

    /**
     * 打卡
     */
    @RequestMapping("/attend")
    @ResponseBody
    public ServerResponse toAttend(@RequestBody Attend attend){
        return iAttendService.toAttend(attend);
    }

    @ResponseBody
    @RequestMapping("/listAttend")
    public ServerResponse<PageInfo> listAttend(@RequestParam("attendStatus") Integer attendStatus,HttpSession session,@RequestParam(value = "currentPage") int currentPage, @RequestParam(value = "pageSize",defaultValue = "10") int pageSize,@RequestParam("rangeDate") String rangeDate){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if(user!=null){
            return iAttendService.listAttend(user.getId(),currentPage,pageSize,rangeDate,attendStatus);
        }
        return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),ResponseCode.NEED_LOGIN.getDesc());
    }

}
